package net.pinnoocle.playshoppc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playdao.entity.shopPc.coupon.CouponListPageVo;
import net.pinnoocle.playdao.entity.shopPc.coupon.CouponListSearchParams;
import net.pinnoocle.playdao.entity.shopPc.coupon.SaveCouponParams;
import net.pinnoocle.playservice.service.impl.CouponServiceImpl;
import net.pinnoocle.playservice.service.impl.GroupServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ye
 * @Description
 * @create 2021-11-01 16:58
 */
@RestController
@RequestMapping("/coupon")
@Api(tags = "优惠券管理")
public class CouponController {

    @Autowired
    CouponServiceImpl couponService;

    @GetMapping("couponList")
    @ApiOperation("优惠券列表")
    public BaseResult<PageModel<CouponListPageVo>> couponList(CouponListSearchParams params){
        return new BaseResult<PageModel<CouponListPageVo>>().ok(couponService.couponList(params));
    }

    @PostMapping("createCoupon")
    @ApiOperation("添加优惠券")
    public BaseResult<String> createCoupon(@Validated @RequestBody SaveCouponParams params){
        boolean result = couponService.createCoupon(params);
        if(result){
            return new BaseResult<String>().success("添加优惠券成功");
        }
        return new BaseResult<String>().error("添加优惠券失败");
    }

    @PostMapping("updateCoupon")
    @ApiOperation("编辑优惠券")
    public BaseResult<String> updateCoupon(@Validated @RequestBody SaveCouponParams params){
        boolean result = couponService.updateCoupon(params);
        if(result){
            return new BaseResult<String>().success("编辑优惠券成功");
        }
        return new BaseResult<String>().error("编辑优惠券失败");
    }

    @GetMapping("deleteCoupon")
    @ApiOperation("删除优惠券")
    public BaseResult<String> deleteCoupon(@RequestParam("couponId") String couponId){
        boolean result = couponService.deleteCoupon(couponId);
        if(result){
            return new BaseResult<String>().success("删除优惠券成功");
        }
        return new BaseResult<String>().error("删除优惠券失败");
    }
}
